package com.freesun.shop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freesun.shop.entity.IndexImg;
import com.freesun.shop.service.IndexImgService;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/indexImg")
public class IndexImgController {

    @Reference(check = false)
    private IndexImgService indexImgService;

    @ApiOperation("轮播图的条件分页查询")
    @GetMapping("/page")
    public ResponseEntity<IPage<IndexImg>> findByPage(IndexImg indexImg, Page<IndexImg> page) {
        IPage<IndexImg> iPage= indexImgService.findByPage(indexImg,page);
        return ResponseEntity.ok(iPage);
    }

    @ApiOperation("轮播图的批量删除")
    @DeleteMapping
    public ResponseEntity<Void> deleteIndexImg(@RequestBody List<Long> ids) {
        indexImgService.removeByIds(ids);
        return ResponseEntity.ok().build();
    }
    @ApiOperation("轮播图的新增")
    @PostMapping
    public ResponseEntity<Void> saveIndexImg(@RequestBody IndexImg indexImg) {
        indexImgService.save(indexImg);
        return ResponseEntity.ok().build();
    }
    @ApiOperation("轮播图的单个查询")
    @GetMapping("/info/{id}")
    public ResponseEntity<IndexImg> saveIndexImg(@PathVariable("id") Long id) {
        IndexImg indexImg = indexImgService.getById(id);
        return ResponseEntity.ok(indexImg);
    }
    @ApiOperation("轮播图的修改")
    @PutMapping
    public ResponseEntity<Void> updateIndexImg(@RequestBody IndexImg indexImg) {
        indexImgService.updateById(indexImg);
        return ResponseEntity.ok().build();
    }
}
